/*
 * Visitor.h
 *
 *  Created on: Jul 17, 2013
 *      Author: m
 */

#ifndef VISITOR_H_
#define VISITOR_H_

#include <unistd.h>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include "application_common.h"
#include "Ticket.h"

#define VISITOR_ID_MAX_LENGTH 20

namespace application
{

struct SerializedVisitor
{
    char m_id[VISITOR_ID_MAX_LENGTH];
    SerializedTicket m_ticket;
};

class Visitor
{
protected:
    visitorId m_id;
    Ticket m_ticket;

public:

    /**
     * Constructor
     *
     * @param id Id del Visitante
     */
    Visitor( visitorId id );

    Visitor( const Visitor &rhs );

    Visitor( SerializedVisitor &serialization );

    /**
     * Destructor
     */
    virtual ~Visitor();

    /**
     * Devuelve el id del pasajero
     *
     * @return El id del pasajero
     */
    visitorId getId();

    Ticket& getTicket();

    void setTicket( const Ticket &ticket );

    void getOnTheBus()
    {
        this->simulateAction();
    }

    void getOffTheBus()
    {
        this->simulateAction();
    }

    SerializedVisitor serialize();

protected:

    // El tiempo está expresado en segundos
    void simulateAction( unsigned int minTime = 0, unsigned int maxTime = 10 )
    {
        unsigned int sleepTime = ( rand() % ( maxTime - minTime ) ) + minTime;

        std::clog << "Simulating Action for " << sleepTime << " seconds." << std::endl;

        sleep( sleepTime );
    }
};

} /* namespace business */
#endif /* VISITOR_H_ */
